(define words
  '("damaging"
   "bewildered"
   "unadvised"
   "callous"
   "vulgar"
   "wish"
   "pedal"
   "guarded"
   "nod"
   "pail"
   "blow"
   "hushed"
   "last"
   "railway"
   "scratch"
   "chin"
   "like"
   "attempt"
   "unaccountable"
   "various"
   "desk"
   "vast"
   "second"
   "marvelous"
   "two"
   "ship"
   "floor"
   "foregoing"
   "bolt"
   "well-off"
   "calm"
   "eye"
   "abiding"
   "accurate"
   "quicksand"
   "recognise"
   "eggnog"
   "jump"
   "curve"
   "sky"
   "frighten"
   "stay"
   "grain"
   "substance"
   "planes"
   "fill"
   "seed"
   "groan"
   "arrogant"
   "acoustic"
   "fixed"
   "brick"
   "silent"
   "magical"
   "tomatoes"
   "sedate"
   "pricey"
   "scarf"
   "office"
   "discussion"
   "toothsome"))

(define (compare-strings s1 s2)
  (compare-lists (map char->integer (string->list s1))
		 (map char->integer (string->list s2))))

(define (and x y)
  (if x y #f))

(define (compare-lists l1 l2)
  (if (and (null? l1) (null? l2))
      'eq
      (if (null? l1)
	  'lt
	  (if (null? l2)
	      'gt
	      (if (< (car l1) (car l2))
		  'lt
		  (if (> (car l1) (car l2))
		      'gt
		      (compare-lists (cdr l1) (cdr l2))))))))

(define (insert-by comparator elt rest)
  (if (null? rest)
      (cons elt '())
      (if (eq? 'lt (comparator elt (car rest)))
	  (cons elt rest)
	  (cons (car rest) (insert-by comparator elt (cdr rest))))))

(define (sort-by comparator list)
  (if (null? list)
      list
      (insert-by comparator (car list) (sort-by comparator (cdr list)))))

(define main
  (for-each print (sort-by compare-strings words)))
